package com.zhixiang.xaec.action.health;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.util.BeanUtil;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.health.HealthFile;
import com.zhixiang.xaec.service.health.HealthFileService;
@Controller
@Scope("prototype")
public class HealthFileAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5673098792377585214L;
	
	private HealthFile healthFile;
	
	@Autowired
	private HealthFileService healthFileService;
	
	public void setHealthFile(HealthFile healthFile){
		this.healthFile=healthFile;
	}
	
	public HealthFile getHealthFile(){
		return healthFile;
	}
	
	public String save() {
		try {
		if(healthFile.getId()!=null){
			HealthFile hf=healthFileService.get(healthFile.getId());
			BeanUtil.copyNotNullProperties(hf, healthFile);
			healthFileService.save(hf);
		}else{		
			healthFileService.save(healthFile);
		}
			
		} catch (Exception e) {
		    e.printStackTrace();
			setMsg("保存失败");
			setSuccess(false);
		}

		  return SUCCESS;
	}


    public String delete()
    {
        try
        {
        String[] ids = getRequest().getParameterValues("ids");
        healthFileService.delete(ids);
        }
        catch (Exception e)
        {
            setSuccess(false);
            setMsg("删除失败");
        }

        return SUCCESS;
    }

    public String get()
    {
    	String id=getRequest().getParameter("id");
        if (StringUtils.isNotEmpty(id))
        {
            setResult(healthFileService.get(Long.valueOf(id)));
        }
        return SUCCESS;
    }
    
    public String list()
    {
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<HealthFile> localList =healthFileService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(localList);
        return SUCCESS;
    } 
}
